import java.io.IOException;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;

public class NumberFormatFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
        // 初始化操作（如果有需要）
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        String number = request.getParameter("num");
        if (number != null && !number.matches("[0-9]+")) {
//            request.getRequestDispatcher("/index.html").forward(request, response);
            response.getWriter().print("请输入有效的拉伯数字");
        } else {
            chain.doFilter(request, response);
        }
    }

    public void destroy() {
        // 清理操作（如果有需要）
    }
}
